package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.EStaffinfo;
import com.xuetang9.t9.hotel.beans.RolePermission;
import com.xuetang9.t9.hotel.services.IPositionService;
import com.xuetang9.t9.hotel.services.IStaffinfoService;
import com.xuetang9.t9.hotel.utils.TokenLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author qin
 * @Date 2020/3/1 11:23
 * @Version 1.0
 **/
@Controller
public class LoginController {
    @Autowired
    private IStaffinfoService staffinfoService;

    @Autowired
    private IPositionService positionService;

    @PostMapping("login")
    @ResponseBody
    public Map<String, Object> login(@RequestParam("login") String user, @RequestParam("pass")String password){
        EStaffinfo staffinfo = staffinfoService.queryOne(user, password);
        if (staffinfo !=null){
            String token = TokenLogin.createToken(staffinfo.getName(),staffinfo.getRank());
            System.out.println(staffinfo.getRank());
//            List<RolePermission> list = positionService.queryName(staffinfo.getRank());
//            System.out.println(list);
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("staff",staffinfo);
            map.put("token",token);
//            map.put("RankList",list);
            return map;
        }else {
            return null;
        }
    }

    @GetMapping("")
    public void tokenVerify(){

    }

}
